import 'package:flutter/material.dart';
import 'package:wx_faxian/pages/chat/index.dart';
import 'package:wx_faxian/pages/discover/index.dart';
import 'package:wx_faxian/pages/friends/index.dart';
import 'package:wx_faxian/pages/mine/index.dart';

class RootPage extends StatefulWidget {
  const RootPage({super.key});

  @override
  State<RootPage> createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  int _currentIndex = 0;
  final List<Widget> _pages = [
    const ChatPage(),
    FriendsPage(),
    const DiscoverPage(),
    const MinePage()
  ];

  final PageController _controller = PageController();

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        // body: _pages[_currentIndex],
        body: PageView(
          // 禁用拖拽滚动
          physics: const NeverScrollableScrollPhysics(),
          controller: _controller,
          children: _pages,
          onPageChanged: (index) {
            setState(() {
              _currentIndex = index;
            });
          },
        ),
        // 底部导航按钮
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          iconSize: 30,
          fixedColor: Colors.green, // 选中颜色
          onTap: (val) {
            setState(() {
              _currentIndex = val;
              _controller.jumpToPage(_currentIndex);
            });
          },
          // 底部tab如若超过3个需要配置
          type: BottomNavigationBarType.fixed,
          items: const [
            BottomNavigationBarItem(
              icon: Image(
                  image: AssetImage('images/weixin.png'),
                  width: 50,
                  height: 50),
              activeIcon: Image(
                  image: AssetImage('images/weixin1.png'),
                  width: 50,
                  height: 50),
              label: '微信',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.bookmark),
              label: '通讯录',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.history),
              label: '发现',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.person_outline),
              label: '我的',
            ),
          ],
        ),
      ),
    );
  }
}
